home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / oleo-1_4.lha / oleo-1.4 / info.c < prev    next >
C/C++ Source or Header  |  1993-05-21  |  4KB  |  178 lines

  1. /*    Copyright (C) 1993 Free Software Foundation, Inc.
  2.  
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7.  
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. GNU General Public License for more details.
  12.  
  13. You should have received a copy of the GNU General Public License
  14. along with this software; see the file COPYING.  If not, write to
  15. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  16.  
  17. #include "global.h"
  18. #include "info.h"
  19. #include "hash.h"
  20. #include "cmd.h"
  21.  
  22. struct hash_control * info_buffers;
  23.  
  24.  
  25. #ifdef __STDC__
  26. void
  27. init_info (void)
  28. #else
  29. void
  30. init_info ()
  31. #endif
  32. {
  33.   info_buffers = hash_new();
  34. }
  35.  
  36. #ifdef __STDC__
  37. struct info_buffer *
  38. find_info (char * name)
  39. #else
  40. struct info_buffer *
  41. find_info (name)
  42.      char * name;
  43. #endif
  44. {
  45.   return (struct info_buffer *)hash_find (info_buffers, name);
  46. }
  47.  
  48.  
  49. #ifdef __STDC__
  50. struct info_buffer * 
  51. find_or_make_info (char * name)
  52. #else
  53. struct info_buffer * 
  54. find_or_make_info (name)
  55.      char * name;
  56. #endif
  57. {
  58.   struct info_buffer * buf =
  59.     (struct info_buffer *)hash_find (info_buffers, name);
  60.   if (buf)
  61.     return buf;
  62.   
  63.   buf = ((struct info_buffer *)
  64.      ck_malloc (sizeof (struct info_buffer) + strlen(name) + 1));
  65.   buf->name = (char *)buf + sizeof (*buf);
  66.   strcpy (buf->name, name);
  67.   buf->len = 0;
  68.   buf->text = 0;
  69.   hash_insert (info_buffers, buf->name, buf);
  70.   return buf;
  71. }
  72.  
  73. #ifdef __STDC__
  74. void
  75. clear_info (struct info_buffer * buf)
  76. #else
  77. void
  78. clear_info (buf)
  79.      struct info_buffer * buf;
  80. #endif
  81. {
  82.   if (buf->text)
  83.     {
  84.       int x;
  85.       int stop = buf->len;
  86.       for (x = 0; x < stop; ++x)
  87.     ck_free (buf->text[x]);
  88.       ck_free (buf->text);
  89.     }
  90.   buf->text = 0;
  91.   buf->len = 0;
  92. }
  93.  
  94. #ifdef __STDC__
  95. void
  96. print_info (struct info_buffer * buf, char * format, ...)
  97. #else
  98. void
  99. print_info (buf, format, va_alist)
  100.      struct info_buffer * buf;
  101.      char * format;
  102.      va_dcl
  103. #endif
  104. {
  105.   va_list ap;
  106.   char txt[1000];
  107.   int len;            /* Length of the new line */
  108.   
  109.   var_start (ap, format);
  110.   vsprintf (txt, format, ap);
  111.   va_end (ap);
  112.   len = strlen (txt);
  113.  
  114.   ++buf->len;            /* Number of lines in the buffer */
  115.   buf->text = (char **)ck_remalloc (buf->text, buf->len * sizeof (char *));
  116.   buf->text[buf->len - 1] = (char *)ck_malloc (len + 1);
  117.   bcopy (txt, buf->text[buf->len - 1], len + 1);
  118. }
  119.  
  120.  
  121.  
  122.  
  123. /* A generic buffer for the use informational commands like show-options */
  124. static struct info_buffer * the_text_buf;
  125.  
  126. #ifdef __STDC__
  127. void
  128. io_text_start (void)
  129. #else
  130. void
  131. io_text_start ()
  132. #endif
  133. {
  134.   the_text_buf = find_or_make_info ("_text");
  135.   clear_info (the_text_buf);
  136. }
  137.  
  138.  
  139.  
  140. #ifdef __STDC__
  141. void
  142. io_text_line (char * format, ...)
  143. #else
  144. void
  145. io_text_line (format, va_alist)
  146.      char * format;
  147.      va_dcl
  148. #endif
  149. {
  150.   va_list ap;
  151.   char txt[1000];
  152.   int len;            /* Length of the new line */
  153.   
  154.   var_start (ap, format);
  155.   vsprintf (txt, format, ap);
  156.   va_end (ap);
  157.   len = strlen (txt);
  158.  
  159.   ++the_text_buf->len;        /* Number of lines in the the_text_buf */
  160.   the_text_buf->text =
  161.     (char **)ck_remalloc (the_text_buf->text,
  162.               the_text_buf->len * sizeof (char *));
  163.   the_text_buf->text[the_text_buf->len - 1] = (char *)ck_malloc (len + 1);
  164.   bcopy (txt, the_text_buf->text[the_text_buf->len - 1], len + 1);
  165. }
  166.  
  167. #ifdef __STDC__
  168. void
  169. io_text_finish (void)
  170. #else
  171. void
  172. io_text_finish ()
  173. #endif
  174. {
  175.   run_string_as_macro ("{view-info _text}");
  176. }
  177.  
  178.